<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="客户姓名:" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="请输入客户姓名" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="手机号码:" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入客户手机号码" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="身份证号码:" prop="citizenIdentity">
        <el-input v-model="queryParams.citizenIdentity" placeholder="请输入客户身份证号码" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="客户备注:" prop="remark">
        <el-input v-model="queryParams.remark" placeholder="请输入客户备注" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>


      <el-form-item label="渠道名称:" prop="channelName">
        <el-input v-model="queryParams.channelName" placeholder="请输入渠道名称" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="贷款状态:" prop="loanStatus">
        <el-select v-model="queryParams.loanStatus" placeholder="贷款状态" clearable style="width: 125px">
          <el-option v-for="dict in dict.type.loan_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="客户状态:" prop="clientStatus">
        <el-select v-model="queryParams.clientStatus" placeholder="客户状态" clearable style="width: 125px">
          <el-option v-for="dict in dict.type.client_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>


      <el-form-item label="注册时间:">

        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>

      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
       
      </el-form-item>
      
    </el-form>

    <el-row>
      <el-col>

        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
        <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>


    <el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="序号" prop="id" width="50" />
      <el-table-column label="姓名" prop="clientName" width="100" />
      <el-table-column label="电话号码" prop="phone" width="100" />
      <el-table-column label="身份证号码" prop="citizenIdentity" width="150" />
      <el-table-column label="注册时间"  width="150" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="上次访问时间"  width="150" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="渠道" prop="channelName" width="50" />
      <el-table-column label="备注" prop="remark" width="50" />
      <el-table-column label="贷款状态" prop="loanStatus" width="100" >
        <template slot-scope="scope">
            <dict-tag :options="dict.type.loan_status" :value="scope.row.loanStatus" />
        </template>
      </el-table-column>

      <el-table-column label="客户状态" prop="clientStatus" width="100">
        <template slot-scope="scope">
            <dict-tag :options="dict.type.client_status" :value="scope.row.clientStatus" />
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link :to="'/client/detailed/index/' + scope.row.id" class="link-type">
            <el-button icon="el-icon-user">查看</el-button>

          </router-link>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>


</template>

<script>
import { findClient } from "@/api/client";

export default {
  dicts: ['loan_status','client_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      clientList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限"
        },
        {
          value: "2",
          label: "自定数据权限"
        },
        {
          value: "3",
          label: "本部门数据权限"
        },
        {
          value: "4",
          label: "本部门及以下数据权限"
        },
        {
          value: "5",
          label: "仅本人数据权限"
        }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        clientName: undefined,
        citizenIdentity: undefined,
        phone: undefined,
        channelName: undefined,
        createTime: undefined,
        lastTime: undefined,
        remark: undefined,
        loanStatus: undefined,
        clientStatus: undefined
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" }
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" }
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查看用户操作 */
    // handleA(row) { 
    //  const id = row.id;
    //  console.log(id)
    //  this.$router.push('/client/detailed/index/'+id);
    // },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      console.log(this.addDateRange(this.queryParams, this.dateRange));
      findClient(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
        console.log(res);
        // debugger
        this.clientList = res.rows;
        this.total = res.total;
        this.loading = false;
      }
      );
    },

    // 角色状态修改
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // console.log(queryParams)
      // debugger
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId)

      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('client/export', {
        ...this.queryParams
      }, `role_${new Date().getTime()}.xlsx`)
    }
  }
}; 
</script>